package org.execute.tool.使用.A提取csv中关键词;

import com.hankcs.hanlp.HanLP;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class StringProcessing1 {
//    public static void main(String[] args) {
////        double v = calculateChinesePercentage("你好，世界！Hello, world!");
////        System.out.println(v);
////        String s = traditionalToSimplified("繁體中文 简体中文 你好，世界！Hello, world!");
////        System.out.println(s);
////        String s1 = simplifiedToTraditional("繁體中文 简体中文 你好，世界！Hello, world!");
////        System.out.println(s1);
////        List<String> simplifiedChineseList = Arrays.asList("简体中文1", "简体中文2", "简体中文3");
////
////        List<String> strings = simplifiedToTraditional(simplifiedChineseList);
////        for (String string : strings) {
////            System.out.print(string);
////        }
////        System.out.println();
////        List<String> stringList = traditionalToSimplified(strings);
////        for (String string : stringList) {
////            System.out.print(string);
////        }
////        System.out.println();
///**
// * 最小的单元
// */
//        List<String> simplifiedChineseList = new ArrayList<>();
//        simplifiedChineseList.add("a");
//        simplifiedChineseList.add("ddcc");
//        simplifiedChineseList.add("bc");
//        simplifiedChineseList.add("aa");
//        simplifiedChineseList.add("aabco");
//        simplifiedChineseList.add("dd");
//        simplifiedChineseList.add("a");
//        List<String> strings = theSmallestUnit(simplifiedChineseList);
//        strings.forEach(System.out::println);
//    }
    /**
     * 计算中文字符的百分比
     * @param input
     * @return
     */
    public static double calculateChinesePercentage(String input) {
        int chineseCount = 0;
        int totalCount = 0;
        for (char c : input.toCharArray()) {
            if (Character.UnicodeScript.of(c) == Character.UnicodeScript.HAN) {
                chineseCount++;
            }
            totalCount++;
        }
        return (double) chineseCount / totalCount;
    }
    /**
     * 简体转繁体
     * @param simplifiedChinese
     * @return
     */
    public static String simplifiedToTraditional(String simplifiedChinese) {
        String traditionalChinese = HanLP.convertToTraditionalChinese(simplifiedChinese);
        return traditionalChinese;
    }
    /**
     * 繁体转简体
     * @param traditionalChinese
     * @return
     */
    public static String traditionalToSimplified(String traditionalChinese) {
        String simplifiedChinese = HanLP.convertToSimplifiedChinese(traditionalChinese);
        return simplifiedChinese;
    }
    /**
     * 简体转繁体
     * @param simplifiedChineseList
     * @return
     */
    public static List<String> simplifiedToTraditional(List<String> simplifiedChineseList) {
        List<String> traditionalChineseList = simplifiedChineseList.stream()
                .map(s -> {
                    return HanLP.convertToTraditionalChinese(s);
                })
                .collect(Collectors.toList());

        return traditionalChineseList;
    }
    /**
     * 繁体转简体
     * @param traditionalChineseList
     * @return
     */
    public static List<String> traditionalToSimplified(List<String> traditionalChineseList) {



        List<String> simplifiedChineseList = traditionalChineseList.stream()
                .map(s -> {
                    return HanLP.convertToSimplifiedChinese(s);
                })
                .collect(Collectors.toList());
        return simplifiedChineseList;
    }

    /**
     * 最小的单元
     * @param checklist
     * @return
     */
    public static List<String>  theSmallestUnit(List<String> checklist) {
        List<String> uniqueList = checklist.stream()
                .distinct()
                .collect(Collectors.toList());
        List<String> strings=new ArrayList<>(uniqueList);
        for (int i = 0; i < uniqueList.size(); i++) {
            String traditionalChinese = uniqueList.get(i);


            strings = theSmallestUnit(traditionalChinese, strings);
        }
        return strings;
    }


   private   static List<String> theSmallestUnit(String s,List<String> checklist) {

        ArrayList<String> strings = new ArrayList<>();
        for (int i = 0; i < checklist.size(); i++) {
            String s1 = checklist.get(i);
            if (!s1.contains(s)) {
                strings.add(checklist.get(i));
            }
            if (checklist.get(i).equals(s)) {
                strings.add(checklist.get(i));
            }
        }

        return strings;
    }
}
